def jiecheng(a):  # 阶乘
    num = 1
    for i in range(1, a + 1):
        num *= i
    return num

sum = 0
# 代入阶乘函数发现i=40的时候最后九位数均是零
for i in range(1, 40):
    sum += jiecheng(i)

print(sum % (10 ** 9))
